package delivery.order.service.utils.response;

import com.alibaba.fastjson2.JSON;

public class ResponseUtils {

    /**
     * 000:成功
     * 001：一般错误
     * 011：session异常
     * 012：token异常
     * 013：免密登录失败
     * 014：全局异常-服务端报错
     * ...
     **/
    public static <T> String generateSucceed(T data) {
        ResponseBean<T> resultBean = new ResponseBean<>();
        resultBean.code = ResponseCode.SUCCESS;
        resultBean.des = "请求成功";
        resultBean.data = data;
        return JSON.toJSONString(resultBean);
    }

    public static <T> String generateFail(String des) {
        ResponseBean<T> resultBean = new ResponseBean<>();
        resultBean.code = ResponseCode.COMMON_ERROR;
        resultBean.des = des;
        return JSON.toJSONString(resultBean);
    }

    public static <T> String generateFail(String code, String des) {
        ResponseBean<T> resultBean = new ResponseBean<>();
        resultBean.code = code;
        resultBean.des = des;
        return JSON.toJSONString(resultBean);
    }


    public static <T> String generateFail(String code, String des, T data) {
        ResponseBean<T> resultBean = new ResponseBean<>();
        resultBean.code = code;
        resultBean.des = des;
        resultBean.data = data;
        return JSON.toJSONString(resultBean);
    }

}
